package com.dragon.design.pattern.structural.compoiste;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dragon
 * @version V1.0.0-RELEASE
 * @date 2019/5/18 15:24
 */
public class CourseCatalog extends CatalogComponent {

    private List<CatalogComponent> items = new ArrayList<>();

    private String name;

    private Integer level;

    public CourseCatalog(List<CatalogComponent> items, String name) {
        this.items = items;
        this.name = name;
    }

    public CourseCatalog(String name) {
        this.name = name;
    }

    public CourseCatalog(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public List<CatalogComponent> getItems() {
        return items;
    }

    public void setItems(List<CatalogComponent> items) {
        this.items = items;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void add(CatalogComponent catalogComponent) {
        items.add(catalogComponent);
    }

    @Override
    public void remove(CatalogComponent catalogComponent) {
        items.remove(catalogComponent);
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public void print() {
        System.out.println(this.name);
        if (items.size() > 0) {
            for (CatalogComponent item : items) {
                if (this.level != null) {
                    for (int i = 0; i < this.level; i++) {
                        System.out.print(" ");
                    }
                }
                item.print();
            }
        }
    }
}
